package com.xc.disk.web.rest;


import com.xc.disk.info.TokenInfo;
import com.xc.disk.bean.FolderBean;
import com.xc.disk.dto.FolderDto;
import com.xc.disk.entity.FolderEntity;
import com.xc.disk.service.FolderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>项目名称: Stars</p>
 * <p>描述: 文件目录信息请求接口</p>
 * <P>创建人: 小程</p>
 * <P>创建人邮箱: 779943476@qq.com</p>
 * <p>创建时间: 2019/8/14</p>
 *
 * @version v1.0
 */
@RestController
public class FolderRest {

    @Autowired
    private FolderService folderService;

    /**
     * 添加文件目录
     *
     * @param token      用户token信息
     * @param folderBean 要添加文件目录信息
     * @return 添加后的数据
     */
    @PostMapping("/folder")
    public FolderEntity createFolder(TokenInfo token, @RequestBody FolderBean folderBean) {
        return folderService.createFolder(token, folderBean);
    }

    /**
     * 修改目录
     *
     * @param token 用户token
     * @param id    目录id
     * @param name  目录名称
     * @return 修改后的文件目录信息
     */
    @PutMapping("/folder/{id}")
    public FolderEntity updateFolder(TokenInfo token, @PathVariable("id") String id, @RequestParam String name) {
        return folderService.updateFolder(token, id, name);
    }

    /**
     * 获取文件和目录集合
     *
     * @param token 用户token信息
     * @param parentId    上级id
     * @return 文件和目录集合
     */
    @GetMapping("/folder/file/list")
    public FolderDto getFolderAndFileList(TokenInfo token, @RequestParam String parentId) {
        return folderService.getFolderFileList(token, parentId);
    }


    /**
     * 根据id集合删除文件和目录
     *
     * @param token     用户token信息
     * @param folderIds 文件目录id集合
     * @param fileIds   文件id集合
     */
    @DeleteMapping(value = "/folder/file")
    public void deleteFolderAndFileByIds(TokenInfo token,
                                         @RequestParam(value = "folderIds", required = false) List<String> folderIds,
                                         @RequestParam(value = "fileIds", required = false) List<String> fileIds) {
        folderService.deleteFolderAndFileByIds(token, folderIds, fileIds);
    }
}
